package com.ruoyi.project.fusion.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.project.fusion.domain.*;
import com.ruoyi.project.fusion.service.DataFusionService;
import com.ruoyi.project.system.domain.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@RestController
@Slf4j
@RequestMapping("/rest/data/management/enterprise")
public class DataFusionController {
    @Autowired
    private DataFusionService dataFusionService;

    @GetMapping("/staff/score/query")
    @Log(title = "获取企业人力管理信息", businessType = BusinessType.OTHER)
    public List<HumanResourceScores> getHumanResourceScores(String chainType, String scenario) {
        return dataFusionService.getHumanResourceScores(chainType, scenario);
    }

    @GetMapping("/business/score/query")
    @Log(title = "获取企业经营状况信息", businessType = BusinessType.OTHER)
    public List<BusinessStatusScores> getBusinessStatusScores(String chainType, String scenario) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String userName = user.getUserName();
        if(Objects.equals(userName, "admin")) {//是系统用户
            return dataFusionService.getBusinessStatusScores(chainType, scenario);
        }
        else {
            return dataFusionService.getPartBusinessStatusScores(chainType, scenario,userName);
        }
    }

    @GetMapping("/compliance/rate/query")
    @Log(title = "获取企业物资管理信息", businessType = BusinessType.OTHER)
    public List<MaterialManagementScores> getMaterialManagementScores(String chainType, String scenario) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String userName = user.getUserName();
        if(Objects.equals(userName, "admin")) {//是系统用户
            return dataFusionService.getMaterialManagementScores(chainType, scenario);
        }
        else {
            return dataFusionService.getPartMaterialManagementScores(chainType, scenario,userName);
        }
    }

    @GetMapping("/quality/query")
    @Log(title = "获取质量信息", businessType = BusinessType.OTHER)
    public List<QualityScores> getQualityScores(String chainType, String scenario) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String userName = user.getUserName();
        if(Objects.equals(userName, "admin")) {//是系统用户
            return dataFusionService.getQualityScores(chainType, scenario);
        }
        else {
            return dataFusionService.getPartQualityScores(chainType, scenario,userName);
        }
    }

    @GetMapping("/price/query")
    @Log(title = "获取成本信息", businessType = BusinessType.OTHER)
    public List<PriceScores> getPriceScores(String chainType, String scenario) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String userName = user.getUserName();
        if(Objects.equals(userName, "admin")) {//是系统用户
            return dataFusionService.getPriceScores(chainType, scenario);
        }
        else {
            return dataFusionService.getPartPriceScores(chainType, scenario,userName);
        }
    }

    @GetMapping("/service/query")
    @Log(title = "获取服务信息", businessType = BusinessType.OTHER)
    public List<ServiceScores> getServiceScores(String chainType, String scenario) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String userName = user.getUserName();
        if(Objects.equals(userName, "admin")) {//是系统用户
            return dataFusionService.getServiceScores(chainType, scenario);
        }
        else {
            return dataFusionService.getPartServiceScores(chainType, scenario,userName);
        }
    }

    @GetMapping("/technology/query")
    public List<TechnologyScores> getTechnologyScores(String chainType, String scenario) {
        return dataFusionService.getTechnologyScores(chainType, scenario);
    }
}
